package com.blue.firecat.utils.excel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class FileUtil {

	public static final String JXL_TEMP_DIR = "/opt/upload/financeManager/Template/temp";
	public static final String JXL_TEMP_DIR_WINDOWS = "d:/opt/upload/financeManager/Template/temp";

	private static final Logger logger = LoggerFactory
			.getLogger(FileUtil.class);

	public static String getJxlTempDir() {
		if (System.getProperty("os.name").indexOf("Windows") > -1) {
			File File = new File(JXL_TEMP_DIR_WINDOWS);
			if (!File.exists()) {
				File.mkdirs();
			}
			return JXL_TEMP_DIR_WINDOWS;
		}
		File File = new File(JXL_TEMP_DIR);
		if (!File.exists()) {
			File.mkdirs();
		}
		return JXL_TEMP_DIR;
	}
	/**
	 * 刪除文件
	 * 
	 * @param file
	 * @return
	 */
	public static boolean delete(File file) {
		if (file != null) {
			try {
				logger.info("删除文件: " + file.getAbsolutePath());
				return file.delete();
			} catch (Exception ex) {
				ex.printStackTrace();
				logger.info("不能删除文件: " + file.getAbsolutePath());
				return false;
			}
		}
		return false;
	}
}
